"""
@Author  : 刘文豪
@desc    : 登录页面
@Time    : 2025/8/10
"""
from selenium.webdriver.common.by import By
from base.base import Base
from util import GetLog


class PageLogin(Base):

    def __init__(self,driver):
        super().__init__(driver)
        # 元素初始化
        self.el_username = (By.XPATH,"//input[@placeholder='请输入账号']")
        self.el_password = (By.XPATH,"//input[@placeholder='请输入密码']")
        self.el_vercode = (By.XPATH, "//input[@placeholder='请输入验证码']")
        self.el_login_btn = (By.XPATH,"//button[@type='button']")

    # 登录完整逻辑
    def page_login(self,value_username: str, value_password: str,value_vercode: str):
        logger = GetLog.get_log()
        try:
            # 输入用户名
            self.base_input(self.el_username, value_username)
            logger.info("登录页面-输入用户名成功")
            # 输入密码
            self.base_input(self.el_password, value_password)
            logger.info("登录页面-输入密码成功")
            # 输入验证码
            self.base_input(self.el_vercode, value_vercode)
            logger.info("登录页面-输入验证码成功")
            # 点击登录按钮
            self.base_click(self.el_login_btn)
            logger.info("登录页面-点击登录按钮成功")
        except Exception as e:
            logger.error("登录页面-操作元素失败")
            raise
